package com.tmsps.ne4spring2.model;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Transient;

import com.tmsps.ne4spring2.util.ClassTools;

public abstract class DbModel implements Serializable {
	@Transient
	private static final long serialVersionUID = 1L;

	public Map<String, Object> map = new HashMap<String, Object>();

	public abstract void setDel(int del);

	// 各种 get set;扩展函数
	public Object get(String key) {
		Field field = ClassTools.getField(this.getClass(), key);
		Object val = null;
		if (field != null) {
			val = ClassTools.getClassVal(field, this);
		} else {
			val = map.get(key);
		}
		return val;
	}

	public Object put(String key, Object val) {
		Field field = ClassTools.getField(this.getClass(), key);
		if (field != null) {
			ClassTools.setClassVal(field, this, val);
		} else {
			map.put(key, val);
		}
		return val;
	}
}
